package com.ruoyi.user.controller;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.user.domain.AppUserRole;
import com.ruoyi.user.service.AppUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
public class AppUserRoleController {
    @Autowired
    private AppUserRoleService appUserRoleService;

    @GetMapping("/list")
    public AjaxResult getUserRole(@RequestParam("appUserRole")AppUserRole appUserRole){
        return AjaxResult.success(appUserRoleService.getAppUserRole(appUserRole));
    }

    @PostMapping("/add/{userId}")
    public AjaxResult addUserRole(@PathVariable("userId") Integer userId){
        AppUserRole appUserRole = new AppUserRole();
        appUserRole.setAppUserId(userId);
        appUserRole.setRoleId(2);
        return AjaxResult.success(appUserRoleService.addAppUserRole(appUserRole));
    }

    @DeleteMapping("/remove/{userId}")
    public AjaxResult removeUserRole(@PathVariable("userId") Integer userId){
        return AjaxResult.success(appUserRoleService.removeAppUserRole(userId));
    }

    @PutMapping("/edit")
    public AjaxResult editUserRole(@RequestBody AppUserRole appUserRole){
        return AjaxResult.success(appUserRoleService.editAppUserRole(appUserRole));
    }

    @GetMapping("/get/{userId}")
    public AjaxResult getRoleId(@PathVariable("userId") Integer userId){
        return AjaxResult.success(appUserRoleService.getRoleId(userId));
    }
}
